package cn.wangzg.viewpagerdemo;

import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.view.MenuItem;

import com.google.android.material.bottomnavigation.BottomNavigationView;

public class MainActivity2 extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main2);
        OneFragment home = OneFragment.newInstance(R.color.red, "home");
        OneFragment msg = OneFragment.newInstance(R.color.yellow, "message");
        OneFragment mine = OneFragment.newInstance(R.color.blue, "mine");
        BottomNavigationView bottomNavigationView = findViewById(R.id.bottomNavigationView);
        bottomNavigationView.setOnNavigationItemSelectedListener(new BottomNavigationView.OnNavigationItemSelectedListener() {
            @Override
            public boolean onNavigationItemSelected(@NonNull MenuItem item) {
                switch (item.getItemId()) {
                    case R.id.home:
                        getSupportFragmentManager()
                                .beginTransaction()
                                .replace(R.id.fl, home)
                                .commit();
                        break;
                    case R.id.msg:
                        getSupportFragmentManager()
                                .beginTransaction()
                                .replace(R.id.fl, msg)
                                .commit();
                        break;
                    case R.id.mine:
                        getSupportFragmentManager()
                                .beginTransaction()
                                .replace(R.id.fl, mine)
                                .commit();
                        break;
                }
                return true;
            }
        });
        bottomNavigationView.setSelectedItemId(R.id.home);
    }
}